package comparisons

import (
	"lesson01/instructions/base"
	"lesson01/rtda"
)

type IfAcmpeq struct {
	base.BranchInstruction
}

func (e *IfAcmpeq) Execute(frame *rtda.Frame) {
	if _acmp(frame) {
		base.Branch(frame, e.Offset)
	}
}

type IfAcmpne struct {
	base.BranchInstruction
}

func (e *IfAcmpne) Execute(frame *rtda.Frame) {
	if !_acmp(frame) {
		base.Branch(frame, e.Offset)
	}
}

func _acmp(frame *rtda.Frame) bool {
	stack := frame.OperandStack()
	ref2 := stack.PopRef()
	ref1 := stack.PopRef()
	return ref1 == ref2
}
